<template>
	<view class="img-list">
		<view class="main">
			<view v-for="(item,index) in list" class="img-item">
				<image class="img" :src="item.img.url" mode=""></image>
				<view class="name">名称：{{item.img.name}}</view>
				<view class="tag">分类：{{item.img.tag}}</view>
				<view class="img-btn">
					<view @click="getAlter" :data-id="item._id" class="btn alter">修改</view>
					<view @click="getDelete" :data-id="item._id" class="btn delete">删除</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:null
			};
		},
		onLoad() {
			this.getList()
			this.juUser()
		},
		methods:{
			juUser(){
				const open = uni.getStorageSync('open')
				const db = uniCloud.database();
				db.collection('bz-boss').where({
					openid:open
				}).get()
				.then(res=>{
					console.log(res.result.data.length,'返回结果')
					const lg = res.result.data.length
					if(lg==0){
						uni.reLaunch({
							url:'/pages/index/index'
						})
					}
				})
			},
			//初始数据
			getList(){
				const db = uniCloud.database();
				db.collection('bz-list').orderBy("img.sjc", "desc").get()
				.then(res=>{
					console.log(res.result.data,'jjjjssss')
					this.list = res.result.data
				})
			},
			//删除
			getDelete(e){
				uni.showModal({
					title:'删除',
					content:'确定删除吗？'
				}).then(res=>{
					console.log(res.confirm)
					if(res.confirm==true){
						const id = e.currentTarget.dataset.id
						const db = uniCloud.database();
						db.collection('bz-list').doc(id).remove().then(res=>{
							console.log(res,'jjjjssss')
							this.getList()
						})
					}
				})

			},
			//修改
			getAlter(){
				
			}
		}
	}
</script>

<style lang="scss">
		.img-list{
			padding: 12rpx;
			.main{
				display: flex;
				flex-wrap: wrap;
				justify-content: space-around;
				.img-item{
					width: 220rpx;
					margin-top: 10rpx;
					.img{
						width: 220rpx;
						height: 380rpx;
						border-radius: 15rpx;
					}
					.name{
						font-size: 26rpx;
					}
					.tag{
						font-size: 26rpx;
					}
					.img-btn{
						display: flex;
						justify-content: space-around;
						.btn{
							margin-top: 8rpx;
							width: 80rpx;
							height: 45rpx;
							font-size: 28rpx;
							background: #9a9a9a;
							text-align: center;
							border-radius: 10rpx;
							line-height: 1.6;
							color: #fff;
						}
						.alter{
							background: #00d200;
						}
						.delete{
							background: #f63b00;
						}
					}
				}
			}
		}
</style>
